package com.example.tongue.ui.Online;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.tongue.R;
import com.example.tongue.ui.Online.Body.Peacebody;
import com.example.tongue.ui.Online.Body.utils.BIMcalculate;

public class Questionnaire extends Activity implements View.OnClickListener {
    private EditText heightCustomer,weightCustomer;
    private Button calculate,nineBody;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_questionnaire);
        //绑定输入框
        heightCustomer=findViewById(R.id.HeightCustomer);
        weightCustomer=findViewById(R.id.WeightCustomer);
        calculate=findViewById(R.id.Calculate);
        nineBody=findViewById(R.id.NineBody);

        //设置监听
        calculate.setOnClickListener(this);
        nineBody.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.Calculate:{
                String hc=heightCustomer.getText().toString();
                String wg=weightCustomer.getText().toString();
                if(hc.equals("")||wg.equals("")){
                    Toast.makeText(Questionnaire.this,"请输入体重或身高",Toast.LENGTH_SHORT).show();

                }else{
                    double height=Double.parseDouble(hc)/100;
                    double weight=Double.parseDouble(wg);
                    double BMI=weight/(height*height);


                    TextView result=(TextView)findViewById(R.id.Result);
                    BIMcalculate biMcalculate=new BIMcalculate(BMI);

                    result.setText("健康指数为："+biMcalculate.BIMresult());

                }



            }
            break;
            case R.id.NineBody:

           { Toast.makeText(Questionnaire.this,"开始体质判断,时间稍长请耐心填写", Toast.LENGTH_LONG).show();
             startActivity(new Intent(Questionnaire.this, Peacebody.class));
            }

        }


    }
}
